package com.treetao.union.core.licence;

import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.treetao.union.core.util.JwtTokenUtil;
import com.treetao.union.core.util.RandomUtils;
import com.treetao.union.core.util.ThreadPoolUtil;

@Component
public class ApplicationReadyEventListener implements  ApplicationListener<ApplicationReadyEvent>  {

	@Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		Licence.licence = JwtTokenUtil.generateToken(RandomUtils.randomCustomUUID());
		System.out.println("启动成功....");
//		ThreadPoolUtil.getPool().execute(new Runnable() {
//			
//			@Override
//			public void run() {
//				while(true) {
//					try {
//						Thread.sleep(10000);//10秒
//					} catch (InterruptedException e) {
//						e.printStackTrace();
//					}
//					if(Licence.licence==null || Licence.licence.length()==0 || JwtTokenUtil.isTokenExpired(Licence.licence)) {
//						event.getApplicationContext().close();
//						System.out.println("=========================================\n授权已过期，请重新启动服务器，或者联系QQ：908608802，购买正式版本！\n================================================");
//					}
//				}
//			}
//		});
	}

}
